/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package interfaces;

import conexion.Operaciones;
import javax.swing.JOptionPane;

/**
 *
 * @author vikko
 */
public class PanelModificaCliente extends javax.swing.JPanel {

    /**
     * Creates new form PanelModificaCliente
     */
    public PanelModificaCliente() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        panel_Clientes = new javax.swing.JPanel();
        jLabel19 = new javax.swing.JLabel();
        jScrollPane11 = new javax.swing.JScrollPane();
        tabla_cliente = new javax.swing.JTable();
        btn_mostrarcliente = new javax.swing.JButton();
        btn_buscarcliente = new javax.swing.JButton();
        btn_eliminarcliente = new javax.swing.JButton();
        btn_modificacliente = new javax.swing.JButton();
        btn_salir = new javax.swing.JButton();

        setMaximumSize(new java.awt.Dimension(800, 579));
        setMinimumSize(new java.awt.Dimension(800, 579));
        setPreferredSize(new java.awt.Dimension(800, 579));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/pc_banner2.png"))); // NOI18N

        panel_Clientes.setBorder(javax.swing.BorderFactory.createTitledBorder("Clientes registrados"));

        jLabel19.setText("Los datos de los clientes registrados son:");

        tabla_cliente.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane11.setViewportView(tabla_cliente);

        btn_mostrarcliente.setText("Mostrar todos");
        btn_mostrarcliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_mostrarclienteActionPerformed(evt);
            }
        });

        btn_buscarcliente.setText("Buscar cliente");
        btn_buscarcliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_buscarclienteActionPerformed(evt);
            }
        });

        btn_eliminarcliente.setText("Eliminar cliente");
        btn_eliminarcliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_eliminarclienteActionPerformed(evt);
            }
        });

        btn_modificacliente.setText("Modificar cliente");
        btn_modificacliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_modificaclienteActionPerformed(evt);
            }
        });

        btn_salir.setText("Salir");
        btn_salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_salirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panel_ClientesLayout = new javax.swing.GroupLayout(panel_Clientes);
        panel_Clientes.setLayout(panel_ClientesLayout);
        panel_ClientesLayout.setHorizontalGroup(
            panel_ClientesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_ClientesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel_ClientesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel_ClientesLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btn_salir)
                        .addGap(39, 39, 39)
                        .addComponent(btn_modificacliente))
                    .addComponent(jScrollPane11)
                    .addGroup(panel_ClientesLayout.createSequentialGroup()
                        .addGroup(panel_ClientesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel19)
                            .addGroup(panel_ClientesLayout.createSequentialGroup()
                                .addComponent(btn_buscarcliente)
                                .addGap(35, 35, 35)
                                .addComponent(btn_mostrarcliente, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(34, 34, 34)
                                .addComponent(btn_eliminarcliente)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        panel_ClientesLayout.setVerticalGroup(
            panel_ClientesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_ClientesLayout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addGroup(panel_ClientesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_mostrarcliente)
                    .addComponent(btn_buscarcliente)
                    .addComponent(btn_eliminarcliente))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel19)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane11, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel_ClientesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_modificacliente)
                    .addComponent(btn_salir))
                .addContainerGap(25, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addComponent(panel_Clientes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panel_Clientes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(74, 74, 74))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btn_mostrarclienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_mostrarclienteActionPerformed
        muestracliente();
    }//GEN-LAST:event_btn_mostrarclienteActionPerformed

    private void btn_eliminarclienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_eliminarclienteActionPerformed
        String cliente= JOptionPane.showInputDialog("Ingresa el Nombre del cliente a eliminar");
        eliminarcliente(cliente);
    }//GEN-LAST:event_btn_eliminarclienteActionPerformed

    private void btn_modificaclienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_modificaclienteActionPerformed
        String cliente= JOptionPane.showInputDialog("Ingresa el Nombre del cliente a modificar");
        String []datos= modificacliente(cliente);
        //  System.out.println("Nombre: "+datos[0]);
        //  System.out.println("Contraseña: "+datos[1]);
        //  System.out.println("Password: "+datos[2]);
        FrameModificaUsuario modifica= new FrameModificaUsuario(datos [0], datos[1], datos[2]);
        modifica.setVisible(true);
    }//GEN-LAST:event_btn_modificaclienteActionPerformed

    private void btn_buscarclienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_buscarclienteActionPerformed
        String cliente= JOptionPane.showInputDialog("Ingresa el Nombre del cliente a buscar");
        buscacliente(cliente);
    }//GEN-LAST:event_btn_buscarclienteActionPerformed

    private void btn_salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_salirActionPerformed
         System.exit(0);
    }//GEN-LAST:event_btn_salirActionPerformed
public void muestracliente(){
       Operaciones oper= new Operaciones();
       tabla_cliente.setModel(oper.consultaTodosUsuarios());     //
    }
    
    public void buscacliente(String user){
        Operaciones oper= new Operaciones();
       tabla_cliente.setModel(oper.buscacliente(user));
    }
    
    public String[] modificacliente(String user){
        Operaciones oper= new Operaciones();
        String []datos= oper.modificarcliente(user);
        return datos;
    }
    
    public void eliminarcliente(String user){
        Operaciones oper= new Operaciones();
        oper.eliminacliente(user);
       tabla_cliente.setModel(oper.consultaTodosUsuarios());//
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_buscarcliente;
    private javax.swing.JButton btn_eliminarcliente;
    private javax.swing.JButton btn_modificacliente;
    private javax.swing.JButton btn_mostrarcliente;
    private javax.swing.JButton btn_salir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JScrollPane jScrollPane11;
    private javax.swing.JPanel panel_Clientes;
    private javax.swing.JTable tabla_cliente;
    // End of variables declaration//GEN-END:variables
}
